<script setup name="Example1">
import {stockGetLogPage} from "@/api/wms/stock";
import {warehouseGetList} from "@/api/wms/warehouse";
import {getCurrentInstance, onMounted, reactive} from "vue";
import {useRoute} from "vue-router";

const {proxy} = getCurrentInstance();
const route = useRoute();

onMounted(() => {
  // pd.queryParams = {...pd.queryParams, ...route.query};
  warehouseGetList({parentId: 0}).then(res => {
    pd.warehouseList = res.data;
  });
  getList();
});

const pd = reactive({
  logList: [],
  warehouseList: [],
  loading: true,
  showSearch: true,
  total: 0,
  daterangeUpdate_time: [],
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    productName: "",
    batchCode: "",
    warehouseId: null
  }
});

/** 查询合作伙伴列表 */
function getList() {
  pd.loading = true;
  if (null != pd.daterangeUpdate_time && '' != pd.daterangeUpdate_time) {
    pd.queryParams.beginTime = pd.daterangeUpdate_time[0];
    pd.queryParams.endTime = pd.daterangeUpdate_time[1];
  }
  stockGetLogPage(pd.queryParams).then(res => {
    pd.logList = res.data;
    pd.total = res.total;
    pd.loading = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  pd.queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  pd.queryParams.beginTime = null;
  pd.queryParams.endTime = null;
  pd.queryParams.name = null;
  pd.daterangeUpdate_time = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

</script>

<template>
  <div class="app-container">
    <el-form :model="pd.queryParams" ref="queryRef" :inline="true" v-show="pd.showSearch" label-width="68px">
      <el-form-item prop="warehouseId">
        <el-select v-model="pd.queryParams.warehouseId" placeholder="请选择仓库" clearable>
          <el-option v-for="item in pd.warehouseList" :key="item.id" :label="item.name" :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item prop="productName">
        <el-input v-model="pd.queryParams.productName" placeholder="请输入产品名称搜索" @keyup.enter="handleQuery"/>
      </el-form-item>
      <el-form-item prop="batchCode">
        <el-input v-model="pd.queryParams.batchCode" placeholder="请输入产品批次号搜索" @keyup.enter="handleQuery"/>
      </el-form-item>
      <el-form-item label="记录时间" style="width: 308px">
        <el-date-picker v-model="pd.daterangeUpdate_time" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
                        start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="Search" @click="handleQuery">搜 索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" v-hasPermi="['wms:stock:export']">导 出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="pd.showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="pd.loading" :data="pd.logList">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="产品名称" align="center" prop="productName"/>
      <el-table-column label="产品规格" align="center" prop="specification"/>
      <el-table-column label="订单类型" align="center" prop="orderTypeId"/>
      <el-table-column label="订单id" align="center" prop="orderId"/>
      <el-table-column label="仓库" align="center" prop="warehouseId" >
        <template #default="scope">
          <dict-tag :options="pd.warehouseList" :value="scope.row.warehouseId" labelName="name" labelValue="id" ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="库位" align="center" prop="areaId"/>
      <el-table-column label="单价" align="center" prop="price"/>
      <el-table-column label="操作之前" align="center" prop="quantityBefore"/>
      <el-table-column label="操作数量" align="center" prop="quantity"/>
      <el-table-column label="计量单位" align="center" prop="measureUnit"/>
      <el-table-column label="产品属性" align="center" prop="attrValue"/>
      <el-table-column label="批次编码" align="center" prop="batchCode"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="创建人" align="center" prop="createBy"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="220">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="pd.total > 0" :total="pd.total" v-model:page="pd.queryParams.pageNum"
                v-model:limit="pd.queryParams.pageSize" @pagination="getList"/>
  </div>
</template>

<style lang='scss' scoped>

</style>